#include<stdio.h>
struct Stu{
	char name[15];
	int c,m,e;
}a[1001];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s %d %d %d",a[i].name,&a[i].c,&a[i].m,&a[i].e);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int ans=abs(a[i].c-a[j].c);
			int ans1=abs(a[i].m-a[j].m);
			int ans2=abs(a[i].e-a[j].e);
			int ans3=abs(a[i].e+a[i].c+a[i].m-a[j].c -a[j].m-a[j].e);
			if(ans<=5&&ans1<=5&&ans2<=5&&ans3<=10){
				if(a[i].name>a[j].name)
				printf("%s %s\n",a[j].name,a[i].name);
				else printf("%s %s\n",a[i].name,a[j].name);
			}
		}
	}
	return 0;
}